package com.yitianyigexiangfa.coap.cbor.cborjava.codec;

import co.nstant.in.cbor.CborDecoder;
import co.nstant.in.cbor.CborException;
import co.nstant.in.cbor.model.DataItem;

import java.io.ByteArrayInputStream;
import java.util.List;

/**
 * @author Bill Lau
 * @date 2017-12-23
 */
public class CborJavaCodec {

    public List<DataItem> decode(byte[] bytes) {
        List<DataItem> dataItemList = null;
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            dataItemList = new CborDecoder(bais).decode();
            for (DataItem item : dataItemList) {
                System.out.println(item.toString());
            }
        } catch (CborException e) {
            e.printStackTrace();
        }
        return dataItemList;
    }
}
